package com.example.showlocation;

import android.R;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.drawable.Icon;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import com.example.showlocation.TextureMapViewActivity;
import com.google.android.material.chip.Chip;

public class SendLocationActivity extends AppCompatActivity {
    Boolean isLocated=false;
    Chip chip;
    String name=null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(com.example.showlocation.R.layout.activity_send_location);
        Log.d(getLocalClassName(), "onCreate(Bundle savedInstanceState)");
    }
    void getLocationSetChip(){
        chip.setText(name);
        chip.setTextColor(Color.parseColor(getString(com.example.showlocation.R.color.getLocationcolor)));
        chip.setChipIconTint( ColorStateList.valueOf ( Color.parseColor(getString(com.example.showlocation.R.color.getLocationcolor))) ) ;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            chip.setCloseIcon( Icon.createWithResource("android",R.drawable.btn_dialog).loadDrawable(getApplicationContext())
            );
            View.OnClickListener onClickListener=new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    isLocated=false;
                    chip.setText(getString(com.example.showlocation.R.string.initText));
                    chip.setTextColor(Color.parseColor(getString(com.example.showlocation.R.color.initcolor)));
                    chip.setChipIconTint( ColorStateList.valueOf ( Color.parseColor(getString(com.example.showlocation.R.color.initcolor))) ) ;
                    chip.setCloseIcon( Icon.createWithResource("android",R.drawable.ic_media_play).loadDrawable(getApplicationContext()));
                    chip.setOnCloseIconClickListener(null);
                }
            };
            chip.setOnCloseIconClickListener(onClickListener);
        };
    }
    @SuppressLint("UseCompatLoadingForDrawables")
    protected void onStart() {
        super.onStart();
        chip=((Chip)findViewById(com.example.showlocation.R.id.chip1));
        Intent intent=getIntent();
        name=intent.getStringExtra("name");
        if (intent.getBooleanExtra("isGetLocation",false)==true){
            isLocated=true;
            getLocationSetChip();
        }else {
            if(name!=null){
                getLocationSetChip();
            }
        }
        Log.d(getLocalClassName()+":", "onStart()");
    }
    protected void onResume() {
        super.onResume();
        Log.d(getLocalClassName()+":", "onResume()");
    }
    protected void onPause() {
        super.onPause();
        Log.d(getLocalClassName()+":", "onPause()");
    }
    protected void onStop() {
        super.onStop();
        Log.d(getLocalClassName()+":", "onStop()");
    }
    protected void onRestart() {
        super.onRestart();
        Log.d(getLocalClassName()+":", "onRestart()");
    }
    protected void onDestroy() {
        super.onDestroy();
        Log.d(getLocalClassName()+":", "onDestroy()");
    }

    @SuppressLint("IntentReset")
    public void sendMessage(View view)  {
            Intent intent=new Intent(this, AddLocationActivity.class);
            if (isLocated){
                intent.putExtra("name",chip.getText());
            }
            startActivity(intent);
            Log.d(getLocalClassName()+":", "sendMessage(View view)");
        /*Intent intent=new Intent(this, ShowMapActivity.class);
        startActivity(intent);*/

    }
    @SuppressLint("IntentReset")
    public void sendMessage_6(View view)  {
        Intent intent=new Intent(this, MapRenderLayerActivity.class);
        startActivity(intent);
    }
    @SuppressLint("IntentReset")
    public void sendMessage_7(View view)  {
        Intent intent=new Intent(this, TextureMapViewActivity.class);
        startActivity(intent);
    }
    @SuppressLint("IntentReset")
    public void Send(View view)  {
        Intent intent=new Intent(this, ContentActivity.class);
        if (isLocated){
            intent.putExtra("isLocated",true);
            intent.putExtra("name",chip.getText());
        }
        else {
            intent.putExtra("isLocated",false);
        }
        startActivity(intent);
    }
    @SuppressLint("IntentReset")
    public void AddMarker(View view)  {
        Intent intent=new Intent(this, MarkerActivity.class);
        startActivity(intent);
    }
    @SuppressLint("IntentReset")
    public void Walking(View view)  {
        Intent intent=new Intent(this, WalkingActivity.class);
        startActivity(intent);
    }
    @SuppressLint("IntentReset")
    public void AddLocation_BD(View view)  {
        Intent intent=new Intent(this, AddLocation_BDActivity.class);
        startActivity(intent);
    }
}